package rapier.sso.server.utils;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;

import rapier.sso.common.utils.ThreadLocalUtil;
import rapier.sso.core.entity.TDbSsoAppEntity;
import rapier.sso.core.model.UserModel;
import rapier.sso.server.constant.RapierComConstant;

public class UserModelUtlis {
	public static UserModel getClientModel(UserModel loginUser) {
		TDbSsoAppEntity appInfo = ThreadLocalUtil.get(RapierComConstant.RAPIER_APP);
		UserModel model = null;
		if (appInfo != null && StringUtils.isNotBlank(appInfo.getUserJson())) {
			JSONObject obj = JSONObject.parseObject(appInfo.getUserJson());
			obj.put("id", "");// 必须存在ID
			rapier.sso.server.utils.BeanUtils.copyProperties2Map(loginUser, obj);
			loginUser = obj.toJavaObject(UserModel.class);
			return loginUser;
		} else {
			model = new UserModel();
			rapier.sso.server.utils.BeanUtils.copyProperties(loginUser, model);
			return model;
		}
	}
}
